package com.ybwh.springboot1.conf;

import java.util.Properties;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.batch.MyBatisCursorItemReader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.pagehelper.PageInterceptor;


@Configuration
@MapperScan("com.ybwh.*.dao*")
public class MybatisConfig {
 
	/**
	 * 分页插件
	 */
	@Bean
	public PageInterceptor pageInterceptor() {
		PageInterceptor pageInterceptor0 = new PageInterceptor();
		Properties properties = new Properties();
		properties.put("helperDialect", "mysql");
		//参数方法调用
		properties.put("supportMethodsArguments", "true");
		
		pageInterceptor0.setProperties(properties);
		return pageInterceptor0;
	}
	
	public static <T> MyBatisCursorItemReader<T> createMyBatisCursorItemReader(SqlSessionFactory sessionFactory,String queryId) {
		MyBatisCursorItemReader<T> cir = new MyBatisCursorItemReader<>();
//		cir.setCurrentItemCount(count);
		cir.setSqlSessionFactory(sessionFactory);
		cir.setQueryId(queryId);
		
		return cir;
	}
	

}